
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { ProfessionalService } from './professional.service';
import { CreateProfessionalDto, BaseProfessionalDto, UpdateProfessionalDto, QueryProfessionalDto, ListProfessionalDto } from './dto/professional.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import {CreateSchoolDto, QuerySchoolDto, UpdateSchoolDto} from "./dto/professional-school.dto";
import {BusinessType} from "../../../common/constant/business.constant";
import {Operlog} from "../../../common/decorators/operlog.decorator";
import {ProfessionalSchoolService} from "./professional-school.service";

@ApiTags('专业关联院校管理')
@Controller('edutation/professional/school')
export class ProfessionalSchoolController {
constructor(private readonly professionalSchoolService: ProfessionalSchoolService) {}

    //============================================专业关联课程

    @ApiOperation({  summary: '获取关联院校列表', })
    @Get('list')
    findSchoolAll(@Query() query:QuerySchoolDto) {
        return this.professionalSchoolService.findAllSchool(query);
    }

    @ApiOperation({  summary: '关联院校-详情',    })
    @ApiDataResponse(BaseProfessionalDto)
    @Get(':id')
    findSchoolOne(@Param('id') id: string) {
        return this.professionalSchoolService.findOneSchool(+id);
    }

    @ApiOperation({  summary: '新增关联院校', })
    @Post()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.INSERT })
    createSchool(@Body() body: CreateSchoolDto,@UserTool() { injectCreate }: UserToolType) {
        return this.professionalSchoolService.createSchool(injectCreate(body));
    }

    @ApiOperation({  summary: '修改关联院校', })
    @Put()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.UPDATE })
    editSchool(@Body() body: UpdateSchoolDto,@UserTool() { injectUpdate }: UserToolType) {
        return this.professionalSchoolService.updateSchool(injectUpdate(body));
    }

    @ApiOperation({  summary: '删除关联院校', })
    @Delete(':ids')
    @Operlog({ businessType: BusinessType.DELETE })
    removeSchool(@Param('ids') ids: string) {
        const idList = ids.split(',').map((id) => +id);
        return this.professionalSchoolService.removeSchool(idList);
    }




}
